/* Copyright 2008 Bas van den Berg
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "yaffut.h"
#include "myassert.h"
#include "TestRoom.h"

#include "StringBuilder.h"
#include "KillStats.h"
#include "MudObject.h"
#include "Room.h"

using namespace std;
using namespace Chronos;

#define TEST_PRINT(a) test(a, __FILE__, __LINE__)

struct KillStatsTest : public KillStats {
    KillStatsTest()
        : creature1("creature1", "")
        , creature2("creature2", "")
        , room("room")
    {
        room.addObject(&creature1);
        room.addObject(&creature2);
    }
    ~KillStatsTest() {
        room.removeObject(&creature1);
        room.removeObject(&creature2);
    }
    void test(const char* expected, const char* caller, int line) {
        print(buffer);
        Assert::assert_str_equal(expected, buffer, caller, line);
        buffer.clear();
    }

    MudObject creature1;
    MudObject creature2;
    StringBuilder buffer;
    TestRoom room;
};


TEST(KillStatsTest, testPrintWithoutKills) {
    TEST_PRINT("");
}


TEST(KillStatsTest, testAddingKills) {
    handleObjectEvent(creature1, MUDMOBILE_DEATH);
    TEST_PRINT("creature1  room  1\n");

    handleObjectEvent(creature1, MUDMOBILE_DEATH);
    TEST_PRINT("creature1  room  2\n");
}


TEST(KillStatsTest, testShouldSortKills) {
    for (int i=0; i<10; i++) handleObjectEvent(creature1, MUDMOBILE_DEATH);
    TEST_PRINT("creature1  room  10\n");

    for (int i=0; i<10; i++) handleObjectEvent(creature2, MUDMOBILE_DEATH);
    TEST_PRINT("creature1  room  10\ncreature2  room  10\n");

    handleObjectEvent(creature2, MUDMOBILE_DEATH);
    TEST_PRINT("creature2  room  11\ncreature1  room  10\n");
}

